package com.hgw.Demo07_ObserverPattern.examples;

/**
 * Data time:2021/12/19 16:06
 * StudentID:2019112118
 * Author:hgw
 * Description: 具体指挥部类，充当具体目标类。
 */
public class ConcreteAllyControlCenter extends AllControlCenter {

    public ConcreteAllyControlCenter(String allyName) {
        System.out.println(allyName + "战队组件成功！");
        System.out.println("-----------------------------");
        this.allyName = allyName;
    }

    // 实现通知方法
    @Override
    public void notifyObserver(String name) {
        System.out.println(this.allyName + "战队紧急通知，盟友" + name + "遭受敌人攻击");
        // 遍历观察者集合，调用每一个盟友（自己除外）的支援方法
        for (Observer obs : players) {
            if (!((Observer)obs).getName().equalsIgnoreCase(name)) {
                ((Observer)obs).help();
            }
        }
    }
}
